<template>
  <div class="printForm">
    <div class="area-header">
      <span class="area-header-title">{{ $t('申请单') }}</span>
    </div>
    <table class="printTable">
      <tr>
        <td class="tit">{{ $t('申请标题') }}</td>
        <td colspan="3"><span :style="{ color: mark.actTitleMark ? '#e6a23c' : '' }">{{ form.actTitle }}</span></td>
      </tr>
      <tr>
        <td class="tit">{{ $t('申请人') }}</td>
        <td>
          <span :style="{ color: mark.applyUserIdMark ? '#e6a23c' : '' }">{{ form.applyUserName }}</span>
        </td>
        <td class="tit">{{ $t('申请时间') }}</td>
        <td><span :style="{ color: mark.applyTimeMark ? '#e6a23c' : '' }">{{ parseTime(form.applyTime) }}</span></td>
      </tr>
      <tr>
        <td class="tit">{{ $t('合同名称') }}</td>
        <td>
          <span :style="{ color: mark.nameMark ? '#e6a23c' : '' }">{{ form.name }}</span>
        </td>
        <td class="tit">{{ $t('合同类型') }}</td>
        <td>
          <el-select v-model="form.type" filterable clearable :class="mark.typeMark ? 'markDifferent' : ''" @change="typeOnChange">
            <el-option
              v-for="dict in typeOptions"
              :key="dict.dictValue"
              :label="$t(dict.dictLabel)"
              :value="dict.dictValue"
            />
          </el-select>
        </td>
      </tr>
      <tr>
        <td class="tit">{{ $t('收付款类型') }}</td>
        <td>
          <el-radio-group v-model="form.isPayment" :class="mark.isPaymentMark ? 'markDifferent_radio markDifferent_radio_label' : ''">
            <el-radio
              v-for="dict in isPaymentOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
              @change="paymentOnChange"
            >{{ $t(dict.dictLabel) }}
            </el-radio>
          </el-radio-group>
        </td>
        <td class="tit">{{ $t('是否用印') }}</td>
        <td>
          <el-radio-group v-model="form.isSeal" :class="mark.isSealMark ? 'markDifferent_radio markDifferent_radio_label' : ''" @change="sealOnChange">
            <el-radio
              v-for="dict in isSealOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
            >{{ $t(dict.dictLabel) }}
            </el-radio>
          </el-radio-group>
        </td>
      </tr>
      <tr v-if="typeShow">
        <td class="tit">
          <span>{{ $t('合同金额') }}{{ $t('金额单位') }}</span>
        </td>
        <td>
          <span>
            <span :style="{ color: mark.moneyMark ? '#e6a23c' : '' }">{{ moneyFormat(form.money, 'w') }}</span>
          </span>
        </td>
        <td class="tit">
          <span>
            {{ $t('年化利率(%)') }}
          </span>
        </td>
        <td>
          <span :style="{ color: mark.interestRateMark ? '#e6a23c' : '' }">{{ moneyFormat(form.interestRate) }}</span>
        </td>
      </tr>
      <tr v-if="typeShow">
        <td class="tit">
          <span>{{ $t('起息日') }}</span>
        </td>
        <td colspan="3">
          <span>
            <span :style="{ color: mark.valueDateMark ? '#e6a23c' : '' }">{{ parseTime(form.valueDate) }}</span>
          </span>
        </td>
      </tr>
      <tr>
        <td class="tit">{{ $t('关联项目') }}</td>
        <td colspan="3">
          {{ form.dealName }}
        </td>
      </tr>
      <tr>
        <td class="tit">{{ $t('合同摘要') }}</td>
        <td colspan="3">
          <span :style="{ color: mark.abstractsMark ? '#e6a23c' : '' }">{{ form.abstracts }}</span>
        </td>
      </tr>
    </table>

    <!--用印明细-->
    <div v-show="form.oaSeal.oaSealDetailList && form.oaSeal.oaSealDetailList.length > 0" v-if="form.isSeal === 'Y'" style="margin-bottom: 20px;">
      <div class="area-header">
        <span class="area-header-title">{{ $t('用印明细') }}</span>
      </div>
      <el-table :data="form.oaSeal.oaSealDetailList" border class="nowrapTable formTable">
        <el-table-column :label="$t('用印主体类型')" align="center">
          <template slot-scope="scope">
            <dictSelect
              v-model="scope.row.investMainType"
              :clearable="true"
              dictionary="main_body_type"
              :class="sealMark[scope.$index] !== undefined && sealMark[scope.$index].investMainTypeMark ? 'markDifferent' : sealMarkId.includes(scope.row.id) ? 'markDifferentNew' : ''"
            />
          </template>
        </el-table-column>
        <el-table-column :label="$t('用印主体')" align="center">
          <template slot-scope="scope">
            <MainBodySelect
              v-model="scope.row.investMain"
              :parameters="scope.row.investMainType"
              :class="sealMark[scope.$index] !== undefined && sealMark[scope.$index].investMainMark ? 'markDifferent' : sealMarkId.includes(scope.row.id) ? 'markDifferentNew' : ''"
            />
          </template>
        </el-table-column>
        <el-table-column :label="$t('用印类型')" align="center">
          <template slot-scope="scope">
            <el-select
              v-model="scope.row.sealType"
              multiple
              :class="sealMark[scope.$index] !== undefined && sealMark[scope.$index].sealTypeMark ? 'selectMoreMark' : sealMarkId.includes(scope.row.id) ? 'selectMoreMarkNew' : ''"
            >
              <el-option
                v-for="dict in sealTypeOptions"
                :key="dict.dictValue"
                :label="$t(dict.dictLabel)"
                :value="dict.dictValue"
              />
            </el-select>
          </template>
        </el-table-column>
        <el-table-column :label="$t('备注')" align="center">
          <template slot-scope="scope">
            <span
              :style="{ color: sealMark[scope.$index] !== undefined && sealMark[scope.$index].remarkMark ? '#e6a23c' : sealMarkId.includes(scope.row.id) ? '#8bc34a' : '' }"
            >{{ scope.row.remark }}</span>
          </template>
        </el-table-column>
      </el-table>

    </div>
    <!-- 签约 主体 -->
    <div style="margin-bottom: 20px;">
      <div class="area-header">
        <span class="area-header-title">{{ $t('签约主体') }}</span>
      </div>
      <el-table :data="form.dealContractInvestDebts" border class="nowrapTable formTable">
        <el-table-column :label="$t('主体类型')" align="center">
          <template slot-scope="scope">
            <dictSelect
              v-model="scope.row.investType"
              :clearable="true"
              dictionary="deal_investment_type"
              :class="investorMark[scope.$index] !== undefined && investorMark[scope.$index].investTypeMark ? 'markMain' : investorMarkId.includes(scope.row.id) ? 'markDifferentNew' : ''"
            />
          </template>
        </el-table-column>
        <el-table-column :label="$t('主体名称')" align="center">
          <template slot-scope="scope">
            <MainBodySelect
              v-model="scope.row.investMain"
              :parameters="scope.row.investType"
              :class="investorMark[scope.$index] !== undefined && investorMark[scope.$index].investMainMark ? 'markMain' : investorMarkId.includes(scope.row.id) ? 'markDifferentNew' : ''"
              @change="investOnChange($event, scope.$index)"
            />
          </template>
        </el-table-column>
        <el-table-column v-if="form.type === 'TZXY'" :label="$t('投资金额')" align="center">
          <template slot-scope="scope">
            <span :style="{ color: (investorMark[scope.$index] !== undefined && investorMark[scope.$index].investmentAmountMark) ? '#e6a23c' : ((investorMarkId.includes(scope.row.id)) ? '#8bc34a' : '') }">
              {{ moneyFormat(scope.row.investmentAmount, 'w') }}
            </span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('备注')" align="center">
          <template slot-scope="scope">
            <span :style="{ color: investorMark[scope.$index] !== undefined && investorMark[scope.$index].remarkMark ? '#e6a23c' : investorMarkId.includes(scope.row.id) ? '#8bc34a' : '' }">
              {{ scope.row.remark }}
            </span>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 收付款计划 -->
    <div v-show="form.dealContractPlanDebts && form.dealContractPlanDebts.length > 0" v-if="form.isPayment !== 'no'" style="margin-bottom: 20px;">
      <div class="area-header">
        <span class="area-header-title">{{ form.isPayment === 'collection' ? '收款' : '付款' }}{{ $t('计划') }}</span>
      </div>
      <el-table :data="form.dealContractPlanDebts" border class="nowrapTable formTable">
        <el-table-column :label="$t('主体名称')" align="center">
          <template slot-scope="scope">
            <el-select
              v-model="scope.row.investId"
              clearable
              size="small"
              :class="planMark[scope.$index] !== undefined && planMark[scope.$index].investIdMark ? 'markDifferent' : planMarkId.includes(scope.row.id) ? 'markDifferentNew' : ''"
            >
              <el-option
                v-for="(item, index) in investOptions"
                :key="index"
                :label="item.investorName"
                :value="item.investorId"
              />
            </el-select>
          </template>
        </el-table-column>
        <el-table-column v-if="form.isPayment === 'payment'" :key="1" :label="$t('预计付款时间')" align="center">
          <template slot-scope="scope">
            <span :style="{ color: planMark[scope.$index] !== undefined && planMark[scope.$index].paymentTimeMark ? '#e6a23c' : planMarkId.includes(scope.row.id) ? '#8bc34a' : '' }">
              {{ parseTime(scope.row.paymentTime) }}
            </span>
          </template>
        </el-table-column>
        <el-table-column v-if="form.isPayment === 'payment'" :key="2" :label="$t('预计付款金额') + $t('金额单位')" align="center">
          <template slot-scope="scope">
            <span :style="{ color: planMark[scope.$index] !== undefined && planMark[scope.$index].paymentMoneyMark ? '#e6a23c' : planMarkId.includes(scope.row.id) ? '#8bc34a' : '' }">
              {{ moneyFormat(scope.row.paymentMoney, 'w') }}
            </span>
          </template>
        </el-table-column>
        <el-table-column v-if="form.isPayment === 'collection'" :key="3" :label="$t('预计收款时间')" align="center">
          <template slot-scope="scope">
            <span :style="{ color: planMark[scope.$index] !== undefined && planMark[scope.$index].collectionTimeMark ? '#e6a23c' : planMarkId.includes(scope.row.id) ? '#8bc34a' : '' }">
              {{ parseTime(scope.row.collectionTime) }}
            </span>
          </template>
        </el-table-column>
        <el-table-column v-if="form.isPayment === 'collection'" :key="4" :label="$t('预计收款金额') + $t('金额单位')" align="center">
          <template slot-scope="scope">
            <span :style="{ color: planMark[scope.$index] !== undefined && planMark[scope.$index].collectionMoneyMark ? '#e6a23c' : planMarkId.includes(scope.row.id) ? '#8bc34a' : '' }">
              {{ moneyFormat(scope.row.collectionMoney, 'w') }}
            </span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('币种')" align="center">
          <template slot-scope="scope">
            <dictSelect
              v-model="scope.row.currency"
              :clearable="true"
              dictionary="currency"
              :class="planMark[scope.$index] !== undefined && planMark[scope.$index].currencyMark ? 'markDifferent' : planMarkId.includes(scope.row.id) ? 'markDifferentNew' : ''"
            />
          </template>
        </el-table-column>
        <el-table-column :label="$t('备注')" align="center">
          <template slot-scope="scope">
            <span :style="{ color: planMark[scope.$index] !== undefined && planMark[scope.$index].remarkMark ? '#e6a23c' : planMarkId.includes(scope.row.id) ? '#8bc34a' : '' }">
              {{ scope.row.remark }}
            </span>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 合同关键条款 -->
    <div style="margin-bottom: 20px;">
      <div class="area-header">
        <span class="area-header-title">{{ $t('合同关键条款') }}</span>
      </div>
      <el-table :data="form.dealTermsDebts" border class="nowrapTable formTable">
        <el-table-column :label="$t('条款类型')" align="center">
          <template slot-scope="scope">
            <dictSelect
              v-model="scope.row.type"
              :clearable="true"
              dictionary="key_terms_tyoe"
              :class="termsMark[scope.$index] !== undefined && termsMark[scope.$index].typeMark ? 'markDifferent' : termsMarkId.includes(scope.row.id) ? 'markDifferentNew' : ''"
            />
          </template>
        </el-table-column>
        <el-table-column :label="$t('条款内容')" align="center">
          <template slot-scope="scope">
            <span :style="{ color: termsMark[scope.$index] !== undefined && termsMark[scope.$index].remarkMark ? '#e6a23c' : termsMarkId.includes(scope.row.id) ? '#8bc34a' : '' }">
              {{ scope.row.remark }}
            </span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('提醒时间')" align="center">
          <template slot-scope="scope">
            <span :style="{ color: termsMark[scope.$index] !== undefined && termsMark[scope.$index].remindTimeMark ? '#e6a23c' : termsMarkId.includes(scope.row.id) ? '#8bc34a' : '' }">
              {{ parseTime(scope.row.remindTime) }}
            </span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('提醒人')" align="center">
          <template slot-scope="scope">
            <span :style="{ color: termsMark[scope.$index] !== undefined && termsMark[scope.$index].remindUserNameMark ? '#e6a23c' : termsMarkId.includes(scope.row.id) ? '#8bc34a' : '' }">
              {{ scope.row.remindUserName }}
            </span>
          </template>
        </el-table-column>
      </el-table>

    </div>
    <!-- 附件列表 -->
    <FileView :list.sync="form.fileList" data-type="deal_contract" :business-id="autoBusinessId($route.query.id, form)" :btn-show="!otherBtnHide" />
    <div style="height: 60px;" />
    <div slot="footer" class="dialog-footer" style="text-align: right;width: 100%;background: white;z-index: 2000;">
      <div v-if="promptLogo === 'NEW'">
        <p style="text-align: center;"><span class="promptLogoClass">{{ $t('新合同') }}</span></p>
      </div>
      <div v-if="promptLogo === 'OLD'">
        <p style="text-align: center;"><span class="promptLogoClass">{{ $t('旧合同') }}</span></p>
      </div>
    </div>
  </div>
</template>

<script>
    import MainBodySelect from '@/components/MainBodySelect/index'
    import { saveDealContractDebt, getDealContractDebt } from '@/api/deal/contract/debt/dealContractDebt'
    import { findByDealId } from '@/api/deal/investment/dealInvestment'
    import { getDealName } from '@/api/base/deal/dealBase'
    import { findFund } from '@/api/fund/fundBase'
    export default {
      components: {
        MainBodySelect
      },
        data() {
            return {
                // 合同类型字典
                typeOptions: [], // 收付款类型字典
                isPaymentOptions: [], // 是否用印字典
                isSealOptions: [], // 表单参数
                sealTypeOptions: [], // 用印类型
                otherBtnHide: false,
                // 项目ID
                dealId: this.$route.query.id,
                form: {},
                // 表单校验
                rules: {
                  applyUserId: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                  ], applyTime: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                  ], name: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                  ], type: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                  ], isPayment: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                  ], isSeal: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                  ], money: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                  ], actTitle: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                  ]
                },
              // 费用明细
                oaSealDetailListRules: {
                  investMainType: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }],
                  investMain: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }],
                  sealType: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }]
                },
              // 签约主体
                dealContractInvestDebtsRules: {
                  investType: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }],
                  investMain: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }]
                },
              // 收付款计划
                dealContractPlanDebtsRules: {
                  investId: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }],
                  paymentTime: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  paymentMoney: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }],
                  collectionTime: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }],
                  collectionMoney: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }]
                },
              // 关键条款
                dealTermsDebtsRules: {
                  name: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }],
                  type: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }],
                  remark: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }]
                },
                // 遮罩层
                loading: false,
                // 操作按钮默认不展示
                buttonShow: true,
                // 根据选择的合同类型判断是否展示合同金额、年化利率、起息日
                typeShow: false,
                // 当前项目投资主体
                investmentOptions: [],
                // 签约主体所选择的主体名称 给 收付款计划使用
                investOptions: [],
                // 全部基金
                fundOptions: [],
                // 新旧合同提示标识
                promptLogo: false,
                // 突出不同字段
                mark: {},
                // 用印标记
                sealMark: {},
                sealMarkId: [],
                // 主体标记
                investorMark: [],
                investorMarkId: [],
                // 收付款计划
                planMark: [],
                planMarkId: [],
                // 关键条款标记
                termsMark: [],
                termsMarkId: [],
                // 附件标记
                fileMark: []
            }
        },
        created() {
            this.getDicts('deal_contract_type').then(response => {
                this.typeOptions = response.data
            })
            this.getDicts('payment_no_deal').then(response => {
                this.isPaymentOptions = response.data
            })
            this.getDicts('sys_yes_no').then(response => {
                this.isSealOptions = response.data
            })
            this.getDicts('seal_type').then(response => {
              this.sealTypeOptions = response.data
            })
            findFund().then(response => {
              this.fundOptions = response.data
            })
            this.$bus.$emit('async_done')
        },
      methods: {
            // 初始化数据
            init(data) {
              this.promptLogo = undefined
              this.initForm(data, () => {})
            },
            initForm(data, callback) {
              this.loading = true
              this.dealId = this.$route.query.id ? this.$route.query.id : data.dealId
                if (data != null && data.id !== undefined) {
                    getDealContractDebt(data.id).then(response => {
                      this.form = Object.assign({}, response.data)
                      this.$set(this.form, 'dealContractInvestDebts', response.data.dealContractInvestDebts)
                      this.$forceUpdate()
                      // 初始化收付款计划主体名称
                      this.investOptions = this.form.dealContractInvestDebts.map((item) => {
                        return {
                          investorId: item.investMain,
                          investorName: item.investMainName
                        }
                      })
                      // 和同比对
                      if (typeof this.$parent.$parent.$parent.parentContractData === 'function') {
                        this.$parent.$parent.$parent.parentContractData(this.form)
                      }
                      callback()
                      this.loading = false
                    })
                } else {
                    this.reset()
                    // 获取当前项目的投资主体
                    findByDealId(this.dealId).then(response => {
                      this.investmentOptions = response.data
                      if (this.investmentOptions && this.investmentOptions.length > 0) {
                        // 初始化签约主体
                        this.investmentOptions.forEach((item) => {
                          this.addInvest(item)
                          const invest = {
                            investorId: item.investorId,
                            investorName: item.investorName
                          }
                          this.investOptions.push(invest)
                          this.loading = false
                        })
                      } else {
                        this.loading = false
                      }
                      callback()
                    })
                }
            },
            // 表单重置
            reset() {
                this.form = {
                id: undefined,
                applyUserId: this.$store.state.user.userId,
                sourceId: undefined,
                dealId: this.dealId,
                applyTime: new Date(),
                name: undefined,
                type: undefined,
                isPayment: 'no',
                isSeal: 'N',
                company: undefined,
                money: undefined,
                payCompletionTime: undefined,
                abstracts: undefined,
                actId: undefined,
                actStatus: '0',
                interestRate: undefined,
                valueDate: undefined,
                remark: undefined,
                createBy: undefined,
                updateBy: undefined,
                createTime: undefined,
                updateTime: undefined,
                delFlag: undefined,
                actTitle: undefined,
                oaSeal: {
                  oaSealDetailList: []
                }, // 用印明细
                dealContractInvestDebts: [], // 签约主体
                dealContractPlanDebts: [], // 收付款计划
                dealTermsDebts: [], // 关键条款
                fileList: [] // 文件上传
                }
                this.resetForm('form')
            },
            // 取消按钮
            cancel() {
                this.$parent.$parent.formOpen = false
                this.$parent.$parent.reset()
            },
            // 关闭form页面
            closeForm() {
                // 关闭form页面遮罩层
                this.loading = false
                // 关闭form页面
                this.$parent.$parent.formOpen = false
                // 刷新list页面
                this.$parent.$parent.getList()
            },
            /** 提交按钮 */
            submitForm: function(type) {
                this.$refs['form'].validate(valid => {
                    // 验证数据
                    if (valid) {
                        // 弹出遮罩层
                        this.loading = true
                        // 保存数据
                        saveDealContractDebt(this.form).then(response => {
                            if (response.code === 200) {
                                // 点击的按钮是保存并启动流程
                                if (type === 'process') {
                                    // 启动流程
                                    this.startProcess(response.data.id)
                                // 点击的仅保存
                                } else {
                                    this.msgSuccess(this.$t('保存成功'))
                                    // 关闭form页面
                                    this.closeForm()
                                }
                            } else {
                                this.msgError(response.msg)
                                this.loading = false
                            }
                        })
                    }
                })
           },
            // 启动流程
           startProcess: async function(dataId) {
               this.loading = false
               var dealName = await getDealName(this.dealId)
               // 启动流程时候传入的参数
               const processData = {}
               // 待办标题
               processData.title = '「' + dealName + '」' + ':' + this.form.actTitle
               // 业务表名
               processData.dataTable = 'deal_contract_debt'
               // 业务ID
               processData.dataId = dataId
               // 业务表单地址(待办页面需要打开的页面)
               processData.formPath = '@/views/debt/contract/dealContractDebtForm'
               processData.viewPath = '@/views/debt/contract/dealContractDebtView'
               // 菜单标识(根据菜单标识判断的走哪个流程)
               processData.menuKey = 'deal_contract_debt'
               this.startProcessByMenu(processData, () => {
                   this.form.actStatus = 'D'
                   this.msgSuccess(this.$t('数据保存成功,流程启动成功'))
                   this.closeForm()
               })
           },
          typeOnChange(val) {
              if (val === 'TZXY' || val === 'BCXY') {
                this.typeShow = true
                this.form.isPayment = 'payment'
              } else {
                this.typeShow = false
                this.form.money = undefined
                this.form.interestRate = undefined
                this.form.valueDate = undefined
              }
          },
          // 添加用印主体
          addSeal(data) {
            var row = {
              id: undefined,
              investMainType: '',
              investMain: '',
              sealType: '',
              remark: ''
            }
            if (data) {
              row = {
                id: undefined,
                investMainType: data.investorType,
                investMain: data.investorId,
                sealType: '',
                remark: ''
              }
            }
            if (!(this.form.oaSeal.oaSealDetailList instanceof Array)) {
              this.$set(this.form.oaSeal, 'oaSealDetailList', [])
            }
            this.$nextTick(() => {
              this.form.oaSeal.oaSealDetailList.push(row)
            })
          },
          delSeal(index) {
            this.form.oaSeal.oaSealDetailList.splice(index, 1)
          },
          sealOnChange(val) {
            this.form.oaSeal.oaSealDetailList = []
            if (!this.form.id && val === 'Y') {
              this.investmentOptions.forEach((item) => {
                this.addSeal(item)
              })
            }
          },
          // 添加签约主体
          addInvest(data) {
            var row = {
              id: undefined,
              investType: '',
              investMain: '',
              remark: ''
            }
            if (data) {
              row = {
                id: undefined,
                investType: data.investorType,
                investMain: data.investorId,
                remark: ''
              }
            }
            // 同时初始化用印明细
            if (!(this.form.dealContractInvestDebts instanceof Array)) {
              this.$set(this.form, 'dealContractInvestDebts', [])
            }
            this.$nextTick(() => {
              this.form.dealContractInvestDebts.push(row)
            })
          },
          // 删除签约主体
          delInvest(row, index) {
            this.form.dealContractInvestDebts.splice(index, 1)
            this.delPlanSelect(row.investMain)
          },
          paymentOnChange() {
            this.form.dealContractPlanDebts = []
          },
          // 添加收付款计划
          addPaymentPlan() {
            const row = {
              id: undefined,
              investId: undefined,
              paymentTime: undefined,
              currency: 'CNY',
              paymentMoney: undefined,
              collectionTime: undefined,
              collectionMoney: undefined
            }
            if (!(this.form.dealContractPlanDebts instanceof Array)) {
              this.$set(this.form, 'dealContractPlanDebts', [])
            }
            this.$nextTick(() => {
              this.form.dealContractPlanDebts.push(row)
            })
          },
          // 签约主体去重 不可以选择重复主体
          investOnChange(val, index) {
            var count = 0
            this.form.dealContractInvestDebts.forEach((item) => {
              if (val === item.investMain) {
                ++count
              }
              if (count > 1) {
                this.msgError(this.$t('签约主体存在重复!'))
                this.form.dealContractInvestDebts.splice(index, 1)
                this.delPlanSelect(val)
                this.addInvest()
              }
            })
            if (count === 1) {
              // 签约主体选择完主体后同步付款计划主体选择
              var item = this.fundOptions.find(item => item.id === val)
              if (item) {
                const invest = {
                  investorId: item.id,
                  investorName: item.fundName
                }
                this.investOptions.push(invest)
              }
            }
          },
          // 删除收付款计划主体名称下拉值
          delPlanSelect(val) {
            var investIndex = this.investOptions.indexOf(item => item.id === val)
            this.investOptions.splice(investIndex, 1)
            for (let i = 0; i < this.form.dealContractPlanDebts.length; i++) {
              if (this.form.dealContractPlanDebts[i].investId === val) {
                this.form.dealContractPlanDebts.splice(i, 1)
              }
            }
          },
          // 计算收付款计划预计付款/收款金额 总额
          totalPaymentPlan(attr) {
            var total = 0
            this.form.dealContractPlanDebts.forEach((item) => {
              total += parseInt(item[attr] === undefined ? 0 : item[attr])
            })
            console.log(total)
            this.form.money = total
          },
          // 删除收付款计划
          delPaymentPlan(index) {
            this.form.dealContractPlanDebts.splice(index, 1)
          },
          // 添加合同关键条款
          addTerms() {
            const row = {
              id: undefined,
              investType: '',
              investMain: '',
              paymentTime: '',
              paymentMoney: 0,
              collectionTime: '',
              collectionMoney: '',
              currency: '',
              stake: '',
              remark: ''
            }
            if (!(this.form.dealTermsDebts instanceof Array)) {
              this.$set(this.form, 'dealTermsDebts', [])
            }
            this.$nextTick(() => {
              this.form.dealTermsDebts.push(row)
            })
          },
          // 删除关键条款
          delTerms(index) {
            this.form.dealTermsDebts.splice(index, 1)
          },
          // 字段合同差异标识
          contractDifferencesMark(data) {
            if (data !== null && data !== undefined) {
              this.mark = data.form
              // 用印
              var sealMarkArr = []
              if (this.form.oaSeal !== undefined && this.form.oaSeal !== null && this.form.oaSeal.oaSealDetailList !== undefined && this.form.oaSeal.oaSealDetailList !== null && data.sealDetail !== undefined && data.sealDetail !== null) {
                this.form.oaSeal.oaSealDetailList.forEach(item => {
                  var flag = true
                  data.sealDetail.forEach(item2 => {
                    if (item.id === item2.id) {
                      sealMarkArr.push(item2)
                      flag = false
                    }
                  })
                  if (flag) {
                    sealMarkArr.push(undefined)
                  }
                })
              }
              this.sealMark = sealMarkArr

              this.sealMarkId = []
              this.sealMark.forEach(item => {
                if (item !== undefined) {
                  this.sealMarkId.push(item.id)
                }
              })
              // 取差集, 获取当前页面里存在但是 后台回来的Id中不存在,这行数据, 就是新增的
              const sealMarkArr1 = this.sealMarkId
              const sealMarkArr2 = this.form.oaSeal.oaSealDetailList === null ? [] : this.form.oaSeal.oaSealDetailList
              var tempSealMarkArr2 = []
              sealMarkArr2.forEach(item => {
                tempSealMarkArr2.push(item.id)
              })
              var sealSet1 = new Set(sealMarkArr1)
              var sealSet2 = new Set(tempSealMarkArr2)
              this.sealMarkId = Array.from(new Set(sealMarkArr1.concat(tempSealMarkArr2).filter(v => !sealSet1.has(v) || !sealSet2.has(v))))
              console.log('用印差集', this.sealMarkId, this.sealMark)

              // 签约主体
              var investorMarkArr = []
              if (this.form.dealContractInvestDebts !== undefined && this.form.dealContractInvestDebts !== null && data.investor !== undefined && data.investor !== null) {
                this.form.dealContractInvestDebts.forEach((item) => {
                  var flag = true
                  data.investor.forEach(item2 => {
                    if (item.id === item2.id) {
                      investorMarkArr.push(item2)
                      flag = false
                    }
                  })
                  if (flag) {
                    investorMarkArr.push(undefined)
                  }
                })
              }
              this.investorMark = investorMarkArr

              this.investorMarkId = []
              this.investorMark.forEach(item => {
                if (item !== undefined) {
                  this.investorMarkId.push(item.id)
                }
              })
              // 取差集, 获取当前页面里存在但是 后台回来的Id中不存在,这行数据, 就是新增的
              const investorMarkArr1 = this.investorMarkId
              const investorMarkArr2 = this.form.dealContractInvestDebts === null ? [] : this.form.dealContractInvestDebts
              var tempInvestorMarkArr2 = []
              investorMarkArr2.forEach(item => {
                tempInvestorMarkArr2.push(item.id)
              })
              var InvestorSet1 = new Set(investorMarkArr1)
              var InvestorSet2 = new Set(tempInvestorMarkArr2)
              this.investorMarkId = Array.from(new Set(investorMarkArr1.concat(tempInvestorMarkArr2).filter(v => !InvestorSet1.has(v) || !InvestorSet2.has(v))))
              console.log('主体差集', this.investorMarkId, this.investorMark)

              // 付款计划
              var planMarkArr = []
              if (this.form.dealContractPlanDebts !== undefined && this.form.dealContractPlanDebts !== null && data.plan !== undefined && data.plan !== null) {
                this.form.dealContractPlanDebts.forEach((item) => {
                  var flag = true
                  data.plan.forEach(item2 => {
                    if (item.id === item2.id) {
                      planMarkArr.push(item2)
                      flag = false
                    }
                  })
                  if (flag) {
                    planMarkArr.push(undefined)
                  }
                })
              }
              this.planMark = planMarkArr
              this.planMarkId = []
              this.planMark.forEach(item => {
                if (item !== undefined) {
                  this.planMarkId.push(item.id)
                }
              })
              // 取差集, 获取当前页面里存在但是 后台回来的Id中不存在,这行数据, 就是新增的
              const planMarkArr1 = this.planMarkId
              const planMarkArr2 = this.form.dealContractPlanDebts === null ? [] : this.form.dealContractPlanDebts
              var tempMarkArr2 = []
              planMarkArr2.forEach(item => {
                tempMarkArr2.push(item.id)
              })
              var planSet1 = new Set(planMarkArr1)
              var planSet2 = new Set(tempMarkArr2)
              this.planMarkId = Array.from(new Set(planMarkArr1.concat(tempMarkArr2).filter(v => !planSet1.has(v) || !planSet2.has(v))))
              console.log('收付款计划差集', this.planMarkId)

              // 关键条款
              var termsMarkArr = []
              if (this.form.dealTermsDebts !== undefined && this.form.dealTermsDebts !== null && data.terms !== undefined && data.terms !== null) {
                this.form.dealTermsDebts.forEach(item => {
                  var flag = true
                  data.terms.forEach(item2 => {
                    if (item.id === item2.id) {
                      termsMarkArr.push(item2)
                      flag = false
                    }
                  })
                  if (flag) {
                    termsMarkArr.push(undefined)
                  }
                })
              }
              this.termsMark = termsMarkArr
              this.termsMarkId = []
              this.termsMark.forEach(item => {
                if (item !== undefined) {
                  this.termsMarkId.push(item.id)
                }
              })
              // 取差集, 获取当前页面里存在但是 后台回来的Id中不存在,这行数据, 就是新增的
              const termsMarkArr1 = this.termsMarkId
              const formTerms = this.form.dealTermsDebts === null ? [] : this.form.dealTermsDebts
              var termsMarkArr2 = []
              formTerms.forEach(item => {
                termsMarkArr2.push(item.id)
              })
              var aSet = new Set(termsMarkArr1)
              var bSet = new Set(termsMarkArr2)
              this.termsMarkId = Array.from(new Set(termsMarkArr1.concat(termsMarkArr2).filter(v => !aSet.has(v) || !bSet.has(v))))
              console.log('关键条款差集', this.termsMarkId)

              // 附件
              var fileMarkArr = []
              if (this.form.fileList !== undefined && this.form.fileList !== null && data.fileList !== undefined && data.fileList !== null) {
                var flag = true
                this.form.fileList.forEach(item => {
                  flag = true
                  data.fileList.forEach(item2 => {
                    if (item.name === item2.name) {
                      fileMarkArr.push(item2)
                      flag = false
                    }
                  })
                  if (flag) {
                    fileMarkArr.push(undefined)
                  }
                })
              }
              this.fileMark = fileMarkArr
            }
          }
        }
    }
</script>

<style scoped>
  .splitter-pane.vertical.splitter-paneR[data-v-815c801c] {
    background-color: white;
  }
  .markDifferent >>> input {
    color: #e6a23c;
  }
  .markDifferentNew >>> input {
    color: #8bc34a;
  }
  .markDifferent_radio >>> .el-radio__input.is-checked .el-radio__inner {
    background-color: #e6a23c;
    border-color: #e6a23c;
  }
  .markDifferent_radio_label >>> .el-radio__label {
    color: #e6a23c;
  }

  .markMain >>> .el-input--medium .el-input__inner {
    color: #e6a23c;
  }
  .selectMoreMark >>> .el-tag.el-tag--info {
    color: #e6a23c;
  }
  .selectMoreMarkNew >>> .el-tag.el-tag--info {
    color: #8bc34a;
  }
  .promptLogoClass {
    border-radius: 7px;
    border: 1px solid #1890ff;
    padding: 5px 20px 5px 20px;
    background: #1890ff;
    color: white;
  }
</style>

